#include "DH_key_init.h"

static unsigned int unused_fsm;




void state_transition(DH_PARAMS *dh_fsm,DH_EVENTS event)
{
 switch(dh_fsm -> fsm_state) 
 {
   case INIT:
     if(event == SENT_EXPONENT_EV)
     {
       dh_fsm -> fsm_state = SENT_EXPONENT;
       dh_fsm -> sent_exponent = 1;
     }
     if(event == RECV_EXPONENT_EV)
     {
       dh_fsm -> fsm_state = RECV_EXPONENT;
       dh_fsm -> recv_exponent = 1;
     }
     
     break;
     
   case SENT_EXPONENT:
     if(event == RECV_EXPONENT_EV)
     {
       dh_fsm -> fsm_state = RECV_EXPONENT;
       dh_fsm -> recv_exponent = 1;
     }
     if(event == EXCHANGE_EV)
     {
      dh_fsm -> fsm_state = EXCHANGE_DONE;
      dh_fsm -> exchange = 1;
     }
     
     break;
   
   case RECV_EXPONENT:
     if(event == SENT_EXPONENT_EV)
     {
       dh_fsm -> fsm_state = SENT_EXPONENT;
       dh_fsm -> recv_exponent = 1;
     }
     if(event == EXCHANGE_EV)
     {
       dh_fsm -> fsm_state = EXCHANGE_DONE;
       dh_fsm -> exchange = 1;
     }  
     
     break;
     
   default :
     break;
   
 }
  
}

int init_DH_global_params(DH_PARAMS *dh_fsm)
{
  dh_fsm->fsm_id=unused_fsm++;
  dh_fsm->fsm_state=INIT;
  dh_fsm->sent_exponent=0;
  dh_fsm->recv_exponent=0;
  dh_fsm->exchange=0;
  dh_fsm->base=2;
  dh_fsm->sent_exponent_notify = NULL;
  dh_fsm->recv_exponent_notify = NULL;
  dh_fsm->exchange_notify = NULL;
  dh_fsm->state_table_transition = state_transition;
  
  
}






int init_DH_key_exchange(void)
{
  
  
  DH_PARAMS dh_fsm;
  
  if(init_DH_global_params(&dh_fsm) != DH_SUCCESS)
    return DH_ERROR;
  
  
}